package org.kernely.stream.userpage;

import java.util.Set;

import org.kernely.security.persistence.User;
import org.kernely.stream.StreamBundle;
import org.kernely.stream.dao.MessageDAO;
import org.kernely.stream.persistence.Message;
import org.kernely.stream.utils.MessageComponent;
import org.kernely.ui.mvp.KernelyEvent;
import org.kernely.ui.mvp.KernelyEventReceiver;
import org.kernely.ui.mvp.KernelyPresenter;

public class StreamFavoritesPresenter extends KernelyPresenter<StreamFavoritesView> {

	/**
	 * Bind method, to do some stuff on the view.
	 */
	@Override
	public void bind() {
	}
	
	/**
	 * Load all the favorites and display them.
	 */
	public void listFavorites(){
		this.view.getFavoritesPanel().removeAllComponents();
		User current = StreamBundle.getSecurityService().getCurrentUser();
		Set<Message> favorites = MessageDAO.getInstance().getFavorites(current);
		
		for (Message message : favorites){
			this.view.getFavoritesPanel().addComponent(new MessageComponent(message, this.view.getApplication()));
		}
	}

}
